<template>
  <view>
    <text>新增项目页面</text>
    <up-button
      type="primary"
      text="定位"
      @click="getIESLocationHandler"
    ></up-button>
    <up-button
      type="primary"
      text="打开地图定位"
      @click="chooseLocationHandler"
    ></up-button>
    <up-button
      type="primary"
      text="跳转系统微信授权管理页"
      @click="openAppAuthorizeSettingHandler"
    ></up-button>
    <up-button
      type="primary"
      text="showToast success"
      @click="() => showToast('提示信息', 'success')"
    ></up-button>
    <up-button
      type="primary"
      text="showToast ERROR"
      @click="() => showToast('提示信息', 'error')"
    ></up-button>
    <up-button
      type="primary"
      text="showLoading"
      @click="() => showLoading()"
    ></up-button>
  </view>

  <CustomToast ref="customToastRef" />
  <CustomLoadingPage ref="customLoadingPageRef" />
</template>

<script setup lang="ts">
// import CustomToast from '@/components/common/CustomToast/CustomToast.vue';
import { getIESLocation } from '@/common/utils'
import { onMounted, ref } from 'vue';
import { ToastTypeEnum } from '@/types/enum';

const customToastRef = ref(null);
const getIESLocationHandler = () => {
  getIESLocation().then(res => {
    console.log('getIESLocation success:', res, customToastRef.value?.name);
    customToastRef.value.showToast('获取定位成功12', ToastTypeEnum.SUCCESS);
    // showToast('获取定位成功1', 'success');
  }).catch(err => {
    customToastRef.value.showToast('定位失败，请检查定位是否打开', ToastTypeEnum.ERROR);
    console.log('getIESLocation err:', err);
  })
}

const chooseLocationHandler = () => {
  uni.chooseLocation({
    success(res) {
      console.log('chooseLocationHandler：', res)
    }
  })
}

const openAppAuthorizeSettingHandler = () => {
  uni.openAppAuthorizeSetting({
    success(res) {
      console.log(res)
    }
  })
}
// const location = getIESLocation();

const customLoadingPageRef = ref(null);
onMounted(() => {
  console.log('location', location);
  setTimeout(() => {
    customLoadingPageRef.value.loadingShow = false;
  }, 2000);
})

const showToast = (message, type = 'default') => {
  uni.showToast({
    title: message,
    icon: type,
    duration: 2000,
  });
}

const showLoading = (message = '加载中...') => {
  uni.showLoading({
    title: message,
    mask: true,
    success(res) {
      setTimeout(() => {
        uni.hideLoading();
      }, 2000);
    }
  });
}

// toast相关代码
// const uToastRef = ref(null);
// const showToast = (message, type = 'default') => {
//   uToastRef.value.show({
//     type,
//     message,
//     duration: 2000,
//   });
// }
</script>

<style></style>
